package app.common.utils.wdt.sdk;

import app.common.utils.wdt.sdk.api.sales.TradeAPI;
import app.common.utils.wdt.sdk.api.sales.dto.TradeQueryRequest;
import app.common.utils.wdt.sdk.api.sales.dto.TradeQueryResponse;
import app.common.utils.wdt.sdk.impl.ApiFactory;
import app.common.utils.wdt.sdk.impl.DefaultClient;
import org.apache.commons.lang3.time.FastDateFormat;

import java.util.ArrayList;
import java.util.List;

/**
 * @author feizns
 * @since 2023/3/16
 */
public abstract class ClientUtils {

    public static final FastDateFormat ISO_DATETIME_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");

    public static final FastDateFormat ORDER_FORMAT = FastDateFormat.getInstance("yyMMddHHmmssSSS");

    private static final String sid = "wdterp30";

    private static final String appkey = "POS";

    private static final String appSecret = "c1fbdd70132de9300d23a05a5f63e150:cc169a95acdaa9ffaed4e9d59f93efaa";

    public static void main(String[] args) {
        //
        // Client client = DefaultClient.get("wdtapi3", "test", "test");

        Client client = DefaultClient.get(sid, "http://47.92.239.46/openapi", appkey, appSecret);

        TradeAPI api = ApiFactory.get(client, TradeAPI.class);

        TradeQueryResponse response = api.query(buildRequest(), new Pager(20, 0, true));

        if ( response == null || response.getTotalCount() <= 0 ) {
            System.out.println("No eligible results!");
            return;
        }

        System.out.println("total: " + response.getTotalCount() + " first trade_no:" + response.getOrders().get(0).getTradeNo());
//        GoodsSearchTest(goodsApi);
    }

    private static TradeQueryRequest buildRequest()
    {
        TradeQueryRequest request = new TradeQueryRequest();
        // request.setSrcTid("tid-D9kO2OooUy");
        request.setTradeNo("JY202007290081");

        List statusList = new ArrayList();
        statusList.add(TradeQueryRequest.STATUS_WMS_CONFIRMED);
        // statusList.add(TradeQueryRequest.STATUS_CANCEL);
        // statusList.add(TradeQueryRequest.STATUS_WAIT_CHECK);
        // request.setStatus(StringUtils.join(statusList, ","));

        // request.setWarehouseNo("warehouse_ygg_01");
        // request.setLogisticsNo("3232323333");
        // request.setStartTime("2019-10-31 00:00:00");
        // request.setEndTime("2019-10-31 01:00:00");

        return request;
    }

}
